#include<iostream>
//各种智能指针的头文件
#include<memory>

using std::cout;
using std::endl;
using std::shared_ptr;

//创建两个类，两个类里面成员对象是互相的shared_ptr

class Parent;
class Child;
class Parent
{
public:

    Parent()
    {
        cout<<"parent"<<endl;
    }
    ~Parent()
    {
        cout<<"~parent"<<endl;
    }

    /* shared_ptr<Child> _spc; */
    std::weak_ptr<Child> _spc;
};

class Child
{
public:
    Child()
    {
        cout<<"chiled"<<endl;
    }
    ~Child()
    {
        cout<<"~Child"<<endl;
    }

    shared_ptr<Parent> _spp;
};

int main()
{
    shared_ptr<Child> ptc(new Child());
    shared_ptr<Parent> ptp(new Parent());
    cout<<"ptc "<<ptc.use_count()<<endl;
    cout<<"ptp "<<ptp.use_count()<<endl;
    ptc->_spp=ptp;
    ptp->_spc=ptc;
    cout<<"ptc "<<ptc.use_count()<<endl;
    cout<<"ptp "<<ptp.use_count()<<endl;
}
